﻿function showErrors(ajaxContext) {
    var response = eval("(" + ajaxContext.get_data() + ")");
    var errorList = ""

    if (typeof (response) == "string") {
        /* Details updated. Update the user name */
        $get("welcomeUserDiv").innerHTML = response;

        /* Clear and any error messages */
        $get("errors").innerHTML = "";
        /* Show success */
        if ($get("successDiv") != null) { $get("successDiv").innerHTML = "Success."; }
        if ($get("SuccessImage") != null) { $get("SuccessImage").style.display = "block"; }
    }
    else {
        /* Clear any success messages */
        $get("successDiv").innerHTML = "";
        if ($get("SuccessImage") != null) { $get("SuccessImage").style.display = "none"; }
        /* Show validation errors */
        errorList = "Invalid input. Please review the following: <br/>";
        
        for (var i = 0; i < response.length; i++) {
            if (response[i] != "") {
                errorList = errorList + "<li>" + response[i] + "</li>";
            }
        }
        $get("errors").innerHTML = errorList;
    }
    return;
}
    

function showAJAXError(ajaxContext) {
    alert("Error in AJAX call");
    alert(ajaxContext.get_data());
}
